const express = require('express');
const cors = require('cors');
const contorller = require('./controllers/dbController');
const mockContoller = require('./controllers/mockController')
const app = express();
app.use(cors());


app.get('/api/goods-list', (req, res, next) => {
  // 获取数据库数据
  contorller.getGoodsList((result) => {
    res.json(result);
  });

});

app.get('/api/goods-list/:id', (req, res, next) => {
  contorller.getGoodsInfo(req.params.id, result => {
    res.json(result);
  })
})

app.get('/api/class-data', (req, res, next) => {
  const data = mockContoller.getClassData();
  res.json(data);
})

// 静态化api文件夹
app.use(express.static('public'))

app.listen(8080, () => {
  console.log('服务器正在监听')
})